package com.starlight.ts_clouddev.controller;

import com.starlight.ts_clouddev.annotition.AuthenticationCheck;
import com.starlight.ts_clouddev.annotition.RoleType;
import com.starlight.ts_clouddev.infrastructure.entity.CloudMirror;
import com.starlight.ts_clouddev.service.CloudMirrorService;
import com.starlight.ts_clouddev.util.CloudResponse;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author yfy2001
 * @date 2023/5/18 15:12
 */
@RestController
@RequestMapping("/mirror")
public class CloudMirrorController {

    @Resource
    private CloudMirrorService cloudMirrorService;

    @PostMapping("/create")
    public CloudResponse<Boolean> create(CloudMirror cloudMirror){
        return CloudResponse.success(cloudMirrorService.save(cloudMirror));
    }

    @PostMapping("/update")
    public CloudResponse<Boolean> update(CloudMirror cloudMirror){
        return CloudResponse.success(cloudMirrorService.updateById(cloudMirror));
    }

    @GetMapping("/read")
    @AuthenticationCheck(roleType = {RoleType.LOGIN})
    public CloudResponse<List<CloudMirror>> read(){
        return CloudResponse.success(cloudMirrorService.list());
    }

    @PostMapping("/delete")
    public CloudResponse<Boolean> delete(CloudMirror cloudMirror){
        return CloudResponse.success(cloudMirrorService.removeById(cloudMirror));
    }
}
